//
//  PickNumSportTableViewViewController.m
//  PlayBall
//
//  Created by Jdd‘s macbook on 13-10-25.
//
//

#import "JddPickNumBDTableView.h"

@interface JddPickNumBDTableView ()

@end

@implementation JddPickNumBDTableView

-(void)viewDidLoad{
    [super viewDidLoad];
    self.sportlotterylist = [[JddSportNumberList alloc] init];
}

-(void)refreshTableView
{
    NSArray *tableData = [self.sResult objectFromJSONString];
    CGRect frame = SPORT_CHILD_VIEW_FRAME;
    //让球胜平负，总进球
    if (self.lottId == LOTTERY_PLAY_METHOD_BD || self.lottId == LOTTERY_PLAY_METHOD_BD_ZJQ) {
        [tableView_RQ_SPF_ZJQ removeFromParentViewController];
        [tableView_RQ_SPF_ZJQ.view removeFromSuperview];
        tableView_RQ_SPF_ZJQ = [[JddRQSPF_ZJQ_TableView alloc] init];
        tableView_RQ_SPF_ZJQ.tableData = tableData;
        tableView_RQ_SPF_ZJQ.delegate = self;
        tableView_RQ_SPF_ZJQ.lottId = self.lottId;
        tableView_RQ_SPF_ZJQ.sportlotterylist = self.sportlotterylist;

        [self addChildViewController:tableView_RQ_SPF_ZJQ];
        tableView_RQ_SPF_ZJQ.view.frame = frame;
        [self.view addSubview:tableView_RQ_SPF_ZJQ.view];
    }
    //比分过关 /半全场过关
    else if (self.lottId == LOTTERY_PLAY_METHOD_BD_BF || self.lottId == LOTTERY_PLAY_METHOD_BD_BQC){
        [bf_tableView removeFromParentViewController];
        [bf_tableView.view removeFromSuperview];
        bf_tableView = [[Jdd_BD_BF_TableView alloc] init];
        bf_tableView.tableData = tableData;
        bf_tableView.delegate = self;
        bf_tableView.lottId = self.lottId;
        bf_tableView.sportlotterylist = self.sportlotterylist;
        [self addChildViewController:bf_tableView];
        bf_tableView.view .frame = frame;
        [self.view addSubview:bf_tableView.view];
    }
    //上下单双
    else if (self.lottId == LOTTERY_PLAY_METHOD_BD_SXDS){
        [sxds_tableView removeFromParentViewController];
        [sxds_tableView.view removeFromSuperview];
        sxds_tableView = [[Jdd_SXDS_TableView alloc] init];
        sxds_tableView.tableData = tableData;
        sxds_tableView.delegate = self;
        sxds_tableView.lottId = self.lottId;
        sxds_tableView.sportlotterylist = self.sportlotterylist;
        [self addChildViewController:sxds_tableView];
        sxds_tableView.view .frame = frame;
        [self.view addSubview:sxds_tableView.view];
    }
}

-(void)selectMatch:(id)sender number:(JddSportNumber*) number1{
    UIButton *button = sender;
    JddSportNumber *number = [[JddSportNumber alloc] init];
    number.code = number1.code;
    number.teamArray = [NSMutableArray arrayWithArray:number1.teamArray];
    number.endTime = number1.endTime;
    number.Hteam= number1.Hteam;
    number.Vteam = number1.Vteam;
    
    if (![self.sportlotterylist BallHasNumber:number]) {
        [button setSelected:NO];
    }else {
        if ([self.sportlotterylist.sportList count]>15) {
            [self.sportlotterylist BallHasNumber:number];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"最多选择15场比赛" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            [button setSelected:NO];
        }else {
            [button setSelected:YES];
        }
        
    }

    NSString *label3Text = @"----";
    if ([self.sportlotterylist.sportList count]>0) {
        JddSportNumber *sportnum1 = [self.sportlotterylist.sportList objectAtIndex:0];
        NSDate *date1 = [JddCommonFunction dateFromString:sportnum1.endTime];
        for (JddSportNumber *sportnum in self.sportlotterylist.sportList) {
            NSDate *date2 = [JddCommonFunction dateFromString:sportnum.endTime];
            date1 = [date2 earlierDate:date1];
        }
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
        label3Text = [dateFormatter stringFromDate:date1];
    }
    NSString *label2Text = [NSString stringWithFormat:@"共选择%d场比赛,截止时间：",[self.sportlotterylist.sportList count]];
    
    [self.delegate performSelector:@selector(selectMatch::) withObject:label2Text withObject:label3Text];
}


@end
